package com.ml.mall.service.remark.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ml.mall.bean.req.remark.RemarkNewDto;
import com.ml.mall.bean.req.remark.RemarkQueryAllDto;
import com.ml.mall.consts.CommonConsts;
import com.ml.mall.entity.remark.SysRemark;
import com.ml.mall.entity.sys.SysUser;
import com.ml.mall.security.JwtUtil;
import com.ml.mall.service.remark.SysRemarkService;
import com.ml.mall.mapper.SysRemarkMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class SysRemarkServiceImpl extends ServiceImpl<SysRemarkMapper, SysRemark>
    implements SysRemarkService{

    @Override
    public boolean save(RemarkNewDto dto) {
        SysUser currentUser = JwtUtil.getCurrentUser();

        SysRemark sysRemark = new SysRemark();
        BeanUtil.copyProperties(dto, sysRemark);
        sysRemark.setCreatorAcc(currentUser.getAcc());
        sysRemark.setCreatorName(currentUser.getName());

        return save(sysRemark);
    }

    @Override
    public List<SysRemark> queryAll(RemarkQueryAllDto dto) {
        LambdaQueryWrapper<SysRemark> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysRemark::getType, dto.getType())
                    .eq(SysRemark::getTarget, dto.getTarget());

        return list(queryWrapper);
    }

    @Override
    public boolean addCompanyRefuseRecord(Long companyId, String refuseReason) {
        RemarkNewDto dto = new RemarkNewDto();

        dto.setTarget(companyId);
        dto.setType(CommonConsts.REMARK_TYPE_COMPANY_REFUSE_RECORD);
        dto.setRemark(refuseReason);

        return save(dto);
    }
}




